#include <QtCore>

#include "boardview.h"
#include "constants.h"

BoardView::BoardView( QWidget* parent ) : QGraphicsView( parent )
{
  setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  setViewportUpdateMode( QGraphicsView::MinimalViewportUpdate );
  setOptimizationFlags( QGraphicsView::DontClipPainter | QGraphicsView::DontSavePainterState | QGraphicsView::DontAdjustForAntialiasing );
};

void BoardView::resizeEvent( QResizeEvent* event )
{
  QSize new_size = event->size();
  qreal minViewSize = qMin( new_size.height(), new_size.width() );
  qreal zoom = minViewSize/( Constants::BOARD_SIZE * Constants::FIELD_SIZE );
  qDebug() << "ZOOM:" << zoom;
  resetMatrix();
  scale( zoom, zoom );
  QGraphicsView::resizeEvent( event );  
}


